package cn.edu.sdjzu.xg.service;


import cn.edu.sdjzu.xg.dao.TeacherDao;

import cn.edu.sdjzu.xg.domain.Teacher;
import cn.edu.sdjzu.xg.util.Condition;
import cn.edu.sdjzu.xg.util.JdbcHelper;
import cn.edu.sdjzu.xg.util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class TeacherService {
    private static TeacherService teacherService =new TeacherService();
    public static TeacherService getInstance(){return teacherService;}
    private static TeacherDao teacherDao =TeacherDao.getInstance();

    public boolean add(Teacher teacher) throws SQLException{
        Connection connection = JdbcHelper.getConn();

        return teacherDao.add(teacher);
    }
    public boolean delete(Integer id)throws SQLException{
        return teacherDao.delete(id);
    }
    public boolean update(Teacher teacher)throws SQLException{
        return teacherDao.update(teacher);
    }


    public Teacher find(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Teacher teacher = teacherDao.find(connection,id);
        JdbcHelper.close(connection);
        return teacher;
    }



    public Collection<Teacher> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException {

        Connection connection = JdbcHelper.getConn();
        Collection<Teacher> teachers = TeacherDao.getInstance().findAll(connection,conditionList,pagination);
        JdbcHelper.close(connection);
        return teachers;
    }

}
